# _*_ coding : utf-8 _*_
# @Time : 2022/1/19 20:53
# @Author : StephenQukry
# @File : urllib_test11代理
# @Project : Test2

import urllib.request
url = 'http://www.baidu.com/baidu?tn=monline_3_dg&ie=utf-8&wd=ip'
headers = {'User-Agent':
               'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0'}

request = urllib.request.Request(url=url,headers=headers)
proxies = {
    'http':'118.24.219.151:16817'}
#response = urllib.request.urlopen(request)
handler = urllib.request.ProxyHandler(proxies=proxies)

opener = urllib.request.build_opener(handler)
response = opener.open(request)
content = response.read().decode('utf-8')

with open('daili.html','w',encoding='utf-8')as fp:
    fp.write(content)